package com.xiaolin.io;

import java.io.*;

/**
 * @ClassName TestBufferedReader
 * @Description TODO
 * @Detail detail
 * @Author MyPC
 * @Date 2020/9/26
 * @Version 1.0
 */
public class TestBufferedReader {
    public static void main(String[] args) throws IOException{
        boolean b = readAndWrite("D:\\1file\\hello.rtf", "D:\\1file\\out.rtf");
        System.out.println(b);
    }

    /**
     * 字符流缓冲流
     * @param origin
     * @param dest
     * @return
     */
    public static boolean readAndWrite(String origin,String dest){
        BufferedReader reader = null;
        BufferedWriter writer=null;
        try {
            reader = new BufferedReader(new InputStreamReader(new FileInputStream("D:\\1file\\hello.rtf"),"GBK"));
            writer=new BufferedWriter(new OutputStreamWriter(new FileOutputStream("D:\\1file\\out.rtf"),"GBK"));
            char[] chars=new char[100];
            int len=0;
            while ((len=reader.read(chars)) !=-1){
                writer.write(chars,0,len);
            }
            return true;
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (reader !=null){
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (writer!=null){
                try {
                    writer.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return false;
    }
}
